home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cenvid / controlc.lib < prev    next >
Text File  |  1995-01-31  |  2KB  |  53 lines

  1. // ControlC.lib - Install CEnvi for DOS 1.009 handler for Ctrl-C
  2. // ver.1          and Ctrl-Break pressed at the keyboard.
  3. //
  4. // InstallBreakHandler() - Installs break handler to catch ctrl-C
  5. //                         or ctrl-break handling.  Sets the
  6. //                         gCtrlBreak global to True.
  7. // RemoveBreakHandler() - Remove control break handler
  8. //
  9. // gCtrlBreak;    Global value set to True if Ctrl-C <CtrlBreak>
  10. //                handler is called.  You can check this flag to
  11. //                see if break was pressed and handle however you
  12. //                wish.
  13.  
  14. gCtrlBreak = False;
  15.  
  16. gBreakHandlerInstalled = False;
  17. gOriginalInterrupt23h = 0;
  18.  
  19. gAsmCode = "\x1E\x57\xBF\x00\x00\x8E\xDF\xBF\x00\x00\xC6\x05\x01\x5F\x1F\xCF";
  20. // PUSH    DS
  21. // PUSH    DI
  22. // MOV     DI,0000
  23. // MOV     DS,DI
  24. // MOV     DI,0000
  25. // MOV     BYTE PTR [DI],01
  26. // POP     DI
  27. // POP     DS
  28. // IRET
  29. gCLI = "\xFA\xCB";
  30. gSTI = "\xFB\xCB";
  31. atexit("RemoveBreakHandler");
  32.  
  33. InstallBreakHandler()
  34. {
  35.    gBreakHandlerInstalled = True;
  36.    BLObPut(gAsmCode,3,segment(pointer(gCtrlBreak)),UWORD16);
  37.    BLObPut(gAsmCode,8,offset(pointer(gCtrlBreak)),UWORD16);
  38.    asm(gCLI);
  39.    gOriginalInterrupt23h = peek(4*0x23,UWORD32);
  40.    poke(4*0x23,pointer(gAsmCode),UWORD32);
  41.    asm(gSTI);
  42. }
  43.  
  44. RemoveBreakHandler()
  45. {
  46.    if ( gBreakHandlerInstalled ) {
  47.       gBreakHandlerInstalled = False;
  48.       asm(gCLI);
  49.       poke(4*0x23,gOriginalInterrupt23h,UWORD32);
  50.       asm(gSTI);
  51.    }
  52. }
  53.